//
//  DeviceListModel.m
//  efairy
//
//  Created by 李锋 on 2019/1/14.
//  Copyright © 2019年 East. All rights reserved.
//

#import "DeviceListModel.h"
#import "EFADeviceModel.h"
#import "NSString+XDNumber.h"


@implementation DeviceListItem
- (void)encodeWithCoder:(NSCoder *)aCoder { [self yy_modelEncodeWithCoder:aCoder]; }
- (instancetype)initWithCoder:(NSCoder *)aDecoder { self = [super init]; return [self yy_modelInitWithCoder:aDecoder]; }

- (NSString *)map_state_str {
    NSString *threeStr = [[EFADeviceProtocolModel sharedInstance] threeStateDescribeWithSt:self.efairydevice_alarm_id];
    return [NSString stringWithFormat:@"%@(%@)", threeStr, self.efairydevice_is_online ? @"在线" : @"离线"];
}

- (NSString *)ccid {
    NSRange range = NSMakeRange(0, self.efairydevice_uuid.length - 6);
    NSString *ccidStr = [self.efairydevice_uuid substringWithRange:[self.efairydevice_uuid rangeOfComposedCharacterSequencesForRange:range]];
    return self.efairydevice_uuid ? ccidStr : @"";
}
- (NSString *)uuid_address {
    NSRange range = NSMakeRange(self.efairydevice_uuid.length - 6, 6);
    NSString *idStr = [self.efairydevice_uuid substringWithRange:[self.efairydevice_uuid rangeOfComposedCharacterSequencesForRange:range]];
    if (idStr.length == 6) {
        NSString *zhujiIDStr = [idStr substringWithRange:NSMakeRange(0, 2)];
        NSString *huiluIDStr = [idStr substringWithRange:NSMakeRange(2, 2)];
        NSString *addreIDStr = [idStr substringWithRange:NSMakeRange(4, 2)];
        idStr = [NSString stringWithFormat:@"%ld-%ld-%ld", (unsigned long)[zhujiIDStr xd_hexStrToInteger], (unsigned long)[huiluIDStr xd_hexStrToInteger], (unsigned long)[addreIDStr xd_hexStrToInteger]];
    }
    return self.efairydevice_uuid ? idStr : @"";
}
@end


@implementation PassagewayInfo
- (void)encodeWithCoder:(NSCoder *)aCoder { [self yy_modelEncodeWithCoder:aCoder]; }
- (instancetype)initWithCoder:(NSCoder *)aDecoder { self = [super init]; return [self yy_modelInitWithCoder:aDecoder]; }
@end

@implementation DeviceRealTimeInfo
- (void)encodeWithCoder:(NSCoder *)aCoder { [self yy_modelEncodeWithCoder:aCoder]; }
- (instancetype)initWithCoder:(NSCoder *)aDecoder { self = [super init]; return [self yy_modelInitWithCoder:aDecoder]; }
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass {
    return @{@"c_data_list" : [PassagewayInfo class]};
}
@end



@implementation DeviceUserList

- (void)encodeWithCoder:(NSCoder *)aCoder { [self yy_modelEncodeWithCoder:aCoder]; }
- (instancetype)initWithCoder:(NSCoder *)aDecoder { self = [super init]; return [self yy_modelInitWithCoder:aDecoder]; }

@end

@implementation DeviceListModel
- (void)encodeWithCoder:(NSCoder *)aCoder { [self yy_modelEncodeWithCoder:aCoder]; }
- (instancetype)initWithCoder:(NSCoder *)aDecoder { self = [super init]; return [self yy_modelInitWithCoder:aDecoder]; }
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass {
    return @{@"device_list" : [DeviceListItem class],
             @"user_list":[DeviceUserList class]};
}
@end
